﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Pointandclick.Objects
{
    class Inventory
    {
        List<InventoryItem> items;
        int horizontalSpacing = 100;
        int verticalPosition = 400;

        /// <summary>
        /// Initializes an empty inventory
        /// </summary>
        public Inventory()
        {
            items = new List<InventoryItem>();
        }

        public void Add(Texture2D image, string key)
        {
            items.Add(new InventoryItem(image, key, new Point((items.Count + 1) * horizontalSpacing, verticalPosition)));
        }

        void AdjustPos()
        {
            for (int i = 0; i<items.Count;i++)
            {
                items[i].Position = new Point((i + 1) * horizontalSpacing, verticalPosition);
            }
        }

        public void Update(MouseState mouse, List<Trigger> triggerList)
        {
            //Updates the inventory
            for (int i = 0; i < items.Count; i++)
            {
                if (items[i].Update(mouse, triggerList))
                {
                    items.RemoveAt(i);
                    AdjustPos();
                }
            }
        }

        public void Draw(SpriteBatch spriteBatch, Color color)
        {
            foreach (InventoryItem item in items)
                item.Draw(spriteBatch, color);
        }

    }
}
